﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.DBUtility;
using Jxym.Common.JSON;
using Newtonsoft.Json;
using Jxym.wlkc2011.Module.Default.model;

namespace Jxym.wlkc2011.Module.Default.SERVER.role
{
    public partial class RoleList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                IList<User_RoleConfig> urcList = null;

                if (Request.Params["userid"] != null)
                {
                    MsSqlDal<User_RoleConfig> iurc = new MsSqlDal<User_RoleConfig>();
                    urcList = iurc.GetList("UserID=" + Convert.ToInt32(Request.Params["userid"]), null, "", 0);
                }

                MsSqlDal<User_Role> iur = new MsSqlDal<User_Role>();
                IList<User_Role> list = iur.GetList("", null, "", 0);

                string str = "[";

                foreach (User_Role d in list)
                {
                    str += "{'checked':" + IsTrue(d.ID, urcList) + ",'ID':" + d.ID + ",'Name':'" + d.Name + "'},";
                }
                Response.Write(str.TrimEnd(',') + "]");
            }
        }

        private string IsTrue(int roleId, IList<User_RoleConfig> list)
        {
            if (list == null)
                return "false";
            foreach (User_RoleConfig urcInfo in list)
            {
                if (urcInfo.RoleID == roleId)
                    return "true";
            }
            return "false";
        }
    }
}